package com.hzsai.service.Impl;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * hzsai 2019/8/1
 * usage:
 **/
@Service
public class ScheduledServiceImpl {

    private  int cnt1 = 1;
    private  int cnt2 = 1;
    private  int cnt3 = 1;

    //@Scheduled(initialDelay = 5000, fixedRate = 5000)
    @Async
    public void job1() {
        System.out.println("Job 1: 当前执行线程：" + "【" + Thread.currentThread().getName() + "】，执行了：" + cnt1 + "次");
        cnt1 += 1;
    }

//    @Scheduled(cron = "0 * * * * *")
    @Async
    public void job2() {
        System.out.println("Job 2: 当前执行线程：" + "【" + Thread.currentThread().getName() + "】，执行了：" + cnt2 + "次");
        cnt2 += 1;
    }

    @Async
    public void job3() {
        System.out.println("当前执行线程：" + "【" + Thread.currentThread().getName() + "】，执行了：" + cnt3 + "次");
        cnt3 += 1;
    }
}
